package com.config;

import com.mapper.repository.mysql.WebsiteVisitorAbnormalRepository;
import com.mapper.repository.mysql.WebsiteVisitorDisableRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class FilterConfig {

    @Autowired
    private WebsiteVisitorAbnormalRepository websiteVisitorAbnormalRepository;

    @Autowired
    private WebsiteVisitorDisableRepository websiteVisitorDisableRepository;

    @Bean
    public FilterRegistrationBean<FilterVisit> loggingFilter() {
        FilterRegistrationBean<FilterVisit> registrationBean = new FilterRegistrationBean<>();
        registrationBean.setFilter(new FilterVisit(websiteVisitorAbnormalRepository,websiteVisitorDisableRepository));
        registrationBean.addUrlPatterns("/*");  // 设置过滤器应用的路径
        registrationBean.setOrder(1);  // 设置过滤器的顺序，数字越小越先执行
        return registrationBean;
    }
}